<template>
	<view class="slp-contant">
		<image
			style="width: 129px; position: absolute; top: 2%; right: 12%"
			src="/static/img/23.png"
			mode="widthFix"
		></image>
		<view>
			<image class="avatar" style="width: 129px" :src="imageurl + imgs" mode="widthFix"></image>
		</view>
		<view class="tit">请先设置登录密码</view>
		<view class="main">
			<u--input
				:adjustPosition="false"
				fontSize="16"
				v-model="pwd.first"
				type="password"
				placeholder="密码"
				border="bottom"
				clearable
			></u--input>
			<u--input
				:adjustPosition="false"
				fontSize="16"
				v-model="pwd.second"
				type="password"
				placeholder="再输入密码"
				border="bottom"
				clearable
			></u--input>
			<view class="flex" style="margin-top: 10px; justify-content: space-between">
				<view class="left flex">
					<view @click="download" style="font-size: 12px; color: #ff3331">下载app</view>
				</view>
				<view class="right">
					<view @click="logina" style="font-size: 12px; color: #ff3331">登陆账号</view>
				</view>
			</view>
			<view @click="confirm" class="flex confirm">{{ cfm.text }}</view>
		</view>
	</view>
</template>

<script>
	import config from '../../common/config/index.js';
	export default {
		data() {
			return {
				imageurl: config.imgurl,
				imgs: '',
				pwd: {
					first: '',
					second: '',
				},
				com_info: '',
				cfm: {
					type: -1,
					text: '',
				},
			};
		},
		mobile: undefined,
		onLoad(e) {
			this.mobile = e.m;
			this.arr_img();
			this.common();
			// #ifdef H5
			let status = navigator.userAgent.toLowerCase();
			if (status.match(/MicroMessenger/i) == 'micromessenger') {
				this.cfm.type = 0;
				this.cfm.text = '确认并关注';
			} else {
				this.cfm.type = 1;
				this.cfm.text = '确认并登录';
			}
			// #endif
			// #ifndef H5
			this.cfm.type = 1;
			this.cfm.text = '确认并登录';
			// #endif
		},
		methods: {
			async arr_img() {
				let res = await this.$http.index.login_img({});
				this.imgs = res.data.logo;
			},
			async common() {
				let res = await this.$http.index.index();
				if (res.code == 1) {
					this.com_info = res.data;
				}
			},
			download() {
				// #ifdef H5
				window.location.href = this.com_info.applink;
				// #endif
				// #ifdef APP-PLUS
				plus.runtime.openURL(this.com_info.applink);
				// #endif
			},
			logina() {
				uni.navigateTo({
					url: 'login',
				});
			},
			async confirm() {
				if (!this.pwd.first || !this.pwd.second) {
					uni.showToast({
						icon: 'none',
						title: '请先填写密码',
					});
					return false;
				}
				if (this.pwd.first !== this.pwd.second) {
					uni.showToast({
						icon: 'none',
						title: '两次密码密码不匹配',
					});
					return false;
				}
				// let mobile = uni.getStorageSync('mobile');
				let res = await this.$http.index.setpwd({ mobile: this.mobile, newpassword: this.pwd.first });
				if (res.code == 1) {
					this.com_info = res.data;
					if (this.cfm.type == 0) {
						uni.navigateTo({
							url: '/pages/home/follow',
						});
					} else {
						uni.switchTab({
							url: '/pages/index/index',
						});
					}
				}
			},
		},
	};
</script>

<style lang="scss">
	.flex {
		display: flex;
		align-items: center;
	}

	.slp-contant {
		background-image: url('@/static/img/bg.png');
		background-repeat: no-repeat;
		background-size: cover;
		padding: 104px 30px 0px;

		.avatar {
			width: 60px;
			border-radius: 15px;
		}

		.tit {
			font-size: 20px;
			font-weight: bold;
			color: #1d1f20;
			margin-top: 15px;
		}

		.u-input {
			padding: 30px 0px 15px !important;
		}

		.input-placeholder {
			font-size: 16px !important;
		}

		.confirm {
			margin-top: 30px;
			justify-content: center;
			background-color: #ff3331;
			box-shadow: 0px 3px 6px 1px #ffbcbb;
			border-radius: 20px;
			height: 40px;
			font-size: 16px;
			color: #fff;
		}
	}
</style>
